﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using System;
using System.Activities;
using System.Activities.Validation;
using System.Activities.XamlIntegration;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DWF.Studio.RemoteCtrls.Proxy
{
    /// <summary>
    /// xaml分析代理
    /// </summary>
    public class XamlAnalyzerProxy : MarshalByRefProxyBase
    {
        public IEnumerable<ValidationInfo> Validate(string workflowFile)
        {
            List<ValidationInfo> infos = new List<ValidationInfo>();
            try
            {
                var settings = new ValidationSettings
                {
                    SkipValidatingRootConfiguration = true
                };
                Activity root = ActivityXamlServices.Load(workflowFile);
                ValidationResults results = ActivityValidationServices.Validate(root, settings);
                
                foreach (var error in results.Errors)
                {
                    infos.Add(new ValidationInfo(error));
                }

                foreach (var warning in results.Warnings)
                {
                    infos.Add(new ValidationInfo(warning));
                }
            }
            catch (Exception ex)
            {
                infos.Add(new ValidationInfo(ex));
            }

            return infos;
        }
    }
}
